package com.chaoxinet.csmall.passport.controller;

import com.chaoxinet.csmall.passport.pojo.dto.AdminAddNewDTO;
import com.chaoxinet.csmall.passport.pojo.dto.AdminLoginDTO;
import com.chaoxinet.csmall.passport.pojo.vo.AdminListItemVO;
import com.chaoxinet.csmall.passport.pojo.vo.RoleListVO;
import com.chaoxinet.csmall.passport.security.LoginPrincipal;
import com.chaoxinet.csmall.passport.service.AdminService;
import com.chaoxinet.csmall.passport.service.RoleService;
import com.chaoxinet.csmall.passport.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 角色控制器
 *
 * @author java@tedu.cn
 * @version 0.0.1
 */
@Slf4j
@Api(tags = "2. 角色管理模块")
@RestController
@RequestMapping("/roles")
public class RoleController {

    @Autowired
    private RoleService service;
    /**
     * 查询管理员列表
     *
     * @return JsonResult<Void> 返回结果
     */
    @ApiOperation("查询角色列表")
    @ApiOperationSupport(order = 420)
    // 权限的检查
    @PreAuthorize("hasAuthority('/ams/admin/read')")
    @GetMapping("")
    public JsonResult<List<RoleListVO>> list() {
        log.debug("接收到查询管角色列表的请求");
        // 调用服务层的list方法查询管理员列表
        List<RoleListVO> roles = service.list();
        log.debug("查询到的管理员列表：{}", roles);
        return JsonResult.ok(roles);
    }
}